package com.example.demo.controller;

import com.example.demo.entity.BaseResponse;
import com.example.demo.model.UserModel;
import com.example.demo.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 这里是面向前端的（浏览器那边）
 */
@RestController
public class UserController {

    /**
     * 依赖注入使用
     */
    @Resource
    private UserService userService;

    /**
     * @param id
     * @return 直接是普通字符串
     */
    @GetMapping("login")
    public String login(Integer id) {
        return userService.loginCheck(id);
    }

    /**
     * @param userModel
     * @return 返回的是json格式字符串
     */
    @PostMapping("register")
    public BaseResponse register(@RequestBody UserModel userModel) {
        return userService.register(userModel);
    }

    @GetMapping("/")
    public String index() {
        return "SpringBoot Demo程序";
    }
}
